package com.withouther.robot.rainingrobot.rest;

import com.withouther.robot.rainingrobot.core.result.CallResult;
import com.withouther.robot.rainingrobot.model.AccessToken;
import com.withouther.robot.rainingrobot.service.RobotRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName RobotRecordController
 * @Auther: tzq
 * @Date: 2020/7/30 21:31
 * @Description:
 */
@RestController
@RequestMapping({"/robotRecord"})
public class RobotRecordController {

    @Autowired
    private RobotRecordService robotRecordService;

    /**
     * 机器人对话接口
     * @param text
     * @return
     */
    @GetMapping("/dialogue")
    public CallResult getDialogue(@RequestParam("text") String text) {
        return CallResult.success(robotRecordService.getDialogue(text));
    }


    /**
     * 初始化验证token接口
     * @param accessToken
     * @return
     */
    @PostMapping("/init/auth")
    public CallResult initAuth(@RequestBody AccessToken accessToken) {
        try {
            return CallResult.success(robotRecordService.initAuth(accessToken));
        } catch (Exception e) {
            e.printStackTrace();
            return CallResult.fail("initAuth Verify token failure accessToken:" + accessToken);
        }
    }
}
